package com.fileDemo;

import java.io.File;
import java.util.HashMap;

/**
 * @Author milian
 * @Date 2021/7/27 0027 16:01
 */
public class test3 {
    public static void main(String[] args) {
        File file = new File("src");
        HashMap<String, Integer> map = new HashMap<>();
        getCount(file,map);
        System.out.println(map);
    }

    private static void getCount(File file, HashMap<String, Integer> map) {
        File[] filesArray = file.listFiles();
        for (File files: filesArray
             ) {
            if (files.isFile()){
                String[] split = files.getName().split("\\.");
                if (split.length==2){
                   if (map.containsKey(split[1])){
                       Integer count = map.get(split[1]);
                       count++;
                       map.put(split[1],count);
                   }else {
                       map.put(split[1],1);
                   }
                }
            }else {
                getCount(files,map);
            }
        }
    }
}
